#ifndef REGISTRY_REGISTRY_H
#define REGISTRY_REGISTRY_H
//******************************************************************************
//*this code is protected by the GNU affero GPLv3
//*author:Sylvain BERTRAND <sylvain.bertrand AT gmail dot com>
//*                        <digital.ragnarok AT gmail dot com>
//******************************************************************************
//------------------------------------------------------------------------------
//name definition of protocol singletons
#define DISPLAY_NAME             0
#define REGISTRY_NAME            1
//from there, the objects get advertised to clients
#define SHM_NAME                 2
#define COMPOSITOR_NAME          3
#define DATA_DEVICE_MANAGER_NAME 4
#define SHELL_NAME               5
#define DEFAULT_SEAT_NAME        6
//------------------------------------------------------------------------------

struct gbl{
  u8 is_singleton;
  s32 n;
  void (*release)(struct gbl *);//can be 0 for singletons

  u8 itf;
  //run once binding is done if not 0
  s8 (*bind_post)(struct client *c,s32 name,u32 id);
  union {
    struct display display;
    struct shm shm;
    struct compositor compositor;
    struct data_device_manager data_device_manager;
    struct shell shell;
    struct seat seat;
    struct output output;
  };
};

#define REGISTRY_N_MAX 32
#ifdef REGISTRY_C
//the object "name" is the index in the array
//1 is the display singleton
struct gbl registry[REGISTRY_N_MAX];
#else
extern struct gbl registry[REGISTRY_N_MAX];
#endif

//TODO:object ref counting may not be of use at all
//check with khr lifetime of ids from non-singleton global registry object
void registry_gbl_ref(struct gbl *g);
s32 registry_gbl_unref(struct gbl *g);
void registry_gbl_generic_release(struct gbl *g);

void registry_init(void);
s8 registry_send(struct client *c,u32 id);
s8 registry_bind(struct client *c,s32 name,u32 id);

void registry_publish(s32 name);
void registry_unpublish(s32 name);
#endif
